package com.example.wanhongli.ledproject;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;

import com.cbtService.AndroidSDK.LedService;

public class LEDActivity extends AppCompatActivity implements View.OnClickListener{
    LedService led_src;
    ImageView iv1,iv2,iv3,iv4;
    public static boolean iflag1 = true;
    public static boolean iflag2 = true;
    public static boolean iflag3 = true;
    public static boolean iflag4 = true;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_led);
        led_src = new LedService();
        iv1=(ImageView)findViewById(R.id.imageView1);
        iv2=(ImageView)findViewById(R.id.imageView2);
        iv3=(ImageView)findViewById(R.id.imageView3);
        iv4=(ImageView)findViewById(R.id.imageView4);
        iv1.setOnClickListener(this);
        iv2.setOnClickListener(this);
        iv3.setOnClickListener(this);
        iv4.setOnClickListener(this);
        iv1.setImageResource(R.drawable.ledoff);

    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.imageView1:{
                if(iflag1){
                    led_src._setLedState(0,1);
                    iv1.setImageResource(R.drawable.ledon);
                    iflag1 = false;
                }
                else{
                    led_src._setLedState(0,0);
                    iv1.setImageResource(R.drawable.ledoff);
                    iflag1 = true;
                }
                break;
            }
            case R.id.imageView2:{
                if(iflag2){
                    led_src._setLedState(1,1);
                    iv2.setImageResource(R.drawable.ledon);
                    iflag2 = false;
                }
                else{
                    led_src._setLedState(1,0);
                    iv2.setImageResource(R.drawable.ledoff);
                    iflag2 = true;
                }
                break;
            }
            case R.id.imageView3:{
                if(iflag3){
                    led_src._setLedState(2,1);
                    iv3.setImageResource(R.drawable.ledon);
                    iflag3 = false;
                }
                else{
                    led_src._setLedState(2,0);
                    iv3.setImageResource(R.drawable.ledoff);
                    iflag3 = true;
                }
                break;
            }
            case R.id.imageView4:{
                if(iflag4){
                    led_src._setLedState(3,1);
                    iv4.setImageResource(R.drawable.ledon);
                    iflag4 = false;
                }
                else{
                    led_src._setLedState(3,0);
                    iv4.setImageResource(R.drawable.ledoff);
                    iflag4 = true;
                }
                break;
            }
        }
    }
}
